# 给定一个字符串，找出其中不含有重复字符的最长子串的长度。

a = "abcabcbb"
b = "bbbbb"
c = "pwwkew"


# start为不重复子串的起始位置，每次循环判断当前字符是否在dicts中
# 若不重复，则下一循环i与start间隔+1，子串长度+1
# 若与已有key重复，则start被赋新值，temp更新为(当前位置与start的间隔)和(已有temp)之间的更大者，
# 且每循环更新重复字符(key)的value

def lengthofLongestSubstring(s):
    temp = 0
    dicts = {}
    start = 0
    for i in range(len(s)):
        if s[i] in dicts and start <= dicts[s[i]]:
            start = dicts[s[i]]+1
        temp = max(i-start+1, temp)
        dicts[s[i]] = i
    print(temp)

lengthofLongestSubstring(a)
lengthofLongestSubstring(b)
lengthofLongestSubstring(c)
